<template>
  <div class="add-friend">
    <div class="top">
      <div class="left">
        <el-avatar :src="item.avatar" :size="50" shape="square"></el-avatar>
      </div>
      <div class="right">
        <span class="name"> 昵称:{{ item.username }}</span>
        <span class="email shallow">邮箱:{{ item.email }}</span>
        <span class="area shallow">地区:{{ item.area }}</span>
        <span class="sign shallow"
          >签名:{{ item.sign ? item.sign : '暂无签名' }}</span
        >
      </div>
    </div>
    <div class="content">
      <div class="nickname">
        <label for="nickname" class="text">备注名:</label>
        <el-input
          v-model="nickname"
          class="input"
          placeholder="请输入备注名称"
        ></el-input>
      </div>
      <div class="look">
        <div class="look_wrapper">
          <span>看我的圈子</span>
          <el-switch v-model="lookme"></el-switch>
        </div>
        <div class="look_wrapper">
          <span>看他的圈子</span>
          <el-switch v-model="lookhim"></el-switch>
        </div>
      </div>
    </div>
    <div class="btn">
      <el-button type="primary" @click="addFriendHandle">添加好友</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
const emit = defineEmits(['addFriendHandle'])
const props = defineProps({
  item: {
    type: Object,
    default: () => {}
  }
})
const nickname = ref<string>('') // 备注名
const lookme = ref<boolean>(false) // 看我的圈子
const lookhim = ref<boolean>(false) // 看他的圈子

onMounted(() => {
  nickname.value = props.item.username
})

// 添加好友
const addFriendHandle = () => {
  emit('addFriendHandle', {
    username: nickname.value,
    lookme: lookme.value ? 1 : 0,
    lookhim: lookhim.value ? 1 : 0,
    id: props.item.id
  })
}
</script>

<style lang="scss" scoped>
.add-friend {
  color: #000;
  line-height: 1.3;
  .top {
    display: flex;

    .left {
      margin-right: 15px;
    }

    .right {
      display: flex;
      flex-direction: column;
    }
  }

  .content {
    margin-top: 15px;
    .nickname {
      display: flex;
      align-items: center;
      .text {
        white-space: nowrap;
        margin-right: 10px;
      }
    }

    .look {
      margin-top: 10px;

      .look_wrapper {
        display: flex;
        justify-content: space-between;
      }
    }
  }

  .btn {
    display: flex;
    justify-content: center;
  }
}
</style>
